package config

import (
	"fmt"
	"io/ioutil"
	"os"
	"sunAb/flag"
	"sunAb/handle"

	"gopkg.in/yaml.v2"
)

func Decode(fConfig flag.FlagData) (Conf, error) {
	fileExists := handle.FileExists(fConfig.FilePath)

	if !fileExists {
		fmt.Println("配置文件不存在")
		os.Exit(0)
	}

	config := Conf{}

	data, err := ioutil.ReadFile(fConfig.FilePath)

	yaml.Unmarshal(data, &config)

	return config, err
}
